package me.sdevil507.supports.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommonUtil {

    /**
     * 去除字符串中的空格、回车、换行符、制表符
     * @param str
     * @return
     */
    public static String replaceBlank(String str) {
        String dest = "";
        if (str!=null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }

    /**
     * 全是汉字的姓名，去除字符串中的空格、回车、换行符、制表符
     * @param str
     * @return
     */
    public static String replaceBlankOfName(String str) {
        String result = "";
        StringBuilder sb = new StringBuilder();
        char[] chars = str.toCharArray();
        for (char c : chars) {
            if (32 == c || 12288 == c) {
                continue;
            }
            sb.append(c);
        }
        String value = sb.toString();

        //判断全是汉字
        String reg = "[\\u4e00-\\u9fa5]+";
        if(value.matches(reg)){
            result = value;
        }else{
            result = str;
        }
        return result;
    }

    /**
     * 是否包含特殊符号
     * @param str
     * @return
     */
    public static boolean isSpecialChar(String str) {
        String regEx = "[ _`[email protected]#$%^&*()+=|{}‘:;‘,\\[\\].<>/?~！@#￥%……&*()——+|{}【】‘；：”“’。，、？]|\n|\r|\t";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.find();
    }

    public static void main(String[] args) {
        String str = " 多对多 汉　字　";
        StringBuilder sb = new StringBuilder();
        char[] chars = str.toCharArray();
        for (char c : chars) {
            if (32 == c || 12288 == c) {
                continue;
            }
            sb.append(c);
        }
        String value = sb.toString();
        System.out.println("----yeo------" + value);
        //判断全是汉字
        String reg = "[\\u4e00-\\u9fa5]+";
        if(value.matches(reg)){
            System.out.println("----all------" + value);
        }else{
            System.out.println("----no------");
        }
    }
}
